<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .el-page-header__content {
            font-size: 18px;
            color: white;
        }
    </style>
</head>
<body>
<div id="app">
    <el-page-header
            style="background-color:#E6A23C;color: white;
                    line-height: 60px"
            @back="goBack" content="新增套餐菜品关联">
    </el-page-header>
    <el-card style="width: 600px;height: 700px;margin: 0 auto">
        <el-form label-width="80px">
            <el-form-item label="餐品选择">
                <el-select placeholder="请选择" v-model="foodPackageLink.foodId">
                    <el-option v-for="c in foodArr"
                               :label="c.name" :value="c.id"></el-option>
                </el-select>
            </el-form-item>


            <el-form-item label="套餐选择">
                <el-select placeholder="请选择" v-model="foodPackageLink.foodPackageId">
                    <el-option v-for="c in foodPackageArr"
                               :label="c.name" :value="c.id"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="时间选择">
                <el-select v-model="foodPackageLink.meal" placeholder="请选择">
                <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
            </el-form-item>

            <el-form-item>
                <el-button type="success" @click="insert()">添加套餐餐品关联</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</div>
</body>
<!--引入axios和vue框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                foodPackageArr:[],
                foodArr:[],
                foodPackageLink:{
                    foodId:"",
                    foodPackageId:"",
                    meal:"",
                    url:"",
                },
                options: [{
                    value: '早餐',
                    label: '早餐'
                }, {
                    value: '午餐',
                    label: '午餐'
                }, {
                    value: '晚餐',
                    label: '晚餐'
                }],

            }
        },
        created:function(){
            //请求所有套餐信息
            axios.get("/foodPackage/select").then(function (response) {
                v.foodPackageArr = response.data;
            })
            axios.get("/food/select").then(function (response) {
                v.foodArr = response.data;
            })
        },
        methods:{
            goBack(){
                //返回上一页面
                history.back();
            },

            insert(){

                //发出添加套餐菜品关联请求
                axios.post("/foodPackageLink/insert",v.foodPackageLink).then(function () {
                    location.href="/admin.html";
                })
            },
        }
    })
</script>
</html>